﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AboutMeWidget : MonoBehaviour
{
    public Text aboutMe;
    public Text homeBackground;
    public Text interest;
    public Text loveView;
    public Text idealCompanion;
    public Button addAboutMe;
    public Button addHomeBackground;
    public Button addInterest;
    public Button addLoveView;
    public Button addIdealCompanion;
    public Button editAboutMe;
    public Button editHomeBackground;
    public Button editInterest;
    public Button editLoveView;
    public Button editIdealCompanion;

    string m_tipsAboutMeStr;
    string m_tipsHomeBackgroundStr;
    string m_tipsInterestStr;
    string m_tipsLoveViewStr;
    string m_tipsIdealStr;

    public void Init(UserInfo userInfo)
    {
        bool isMe = userInfo.userId == MGame.instance.MUser.id;

        if (string.IsNullOrEmpty(userInfo.aboutMe))
        {
            m_tipsAboutMeStr = "介绍下自己的性格、习惯、优缺点等";
            if (isMe)
                aboutMe.text = m_tipsAboutMeStr;
            else
                aboutMe.text = "未填写";
            addAboutMe.gameObject.SetActive(isMe);
            editAboutMe.gameObject.SetActive(false);

        }
        else
        {
            m_tipsAboutMeStr = "";
            aboutMe.text = userInfo.aboutMe;
            addAboutMe.gameObject.SetActive(false);
            editAboutMe.gameObject.SetActive(isMe);
        }
        if (string.IsNullOrEmpty(userInfo.familyBackground))
        {
            m_tipsHomeBackgroundStr = "介绍下父母职业，比如经商家庭，普通家庭，高知家庭等";
            if (isMe)
                homeBackground.text = m_tipsHomeBackgroundStr;
            else
                homeBackground.text = "未填写";
            addHomeBackground.gameObject.SetActive(isMe);
            editHomeBackground.gameObject.SetActive(false);
        }
        else
        {
            m_tipsHomeBackgroundStr = "";
            homeBackground.text = userInfo.familyBackground;
            addHomeBackground.gameObject.SetActive(false);
            editHomeBackground.gameObject.SetActive(isMe);
        }
        if (string.IsNullOrEmpty(userInfo.interest))
        {
            m_tipsInterestStr = "业余喜欢做些什么";
            if (isMe)
                interest.text = m_tipsInterestStr;
            else
                interest.text = "未填写";
            addInterest.gameObject.SetActive(isMe);
            editInterest.gameObject.SetActive(false);
        }
        else
        {
            m_tipsInterestStr = "";
            interest.text = userInfo.interest;
            addInterest.gameObject.SetActive(false);
            editInterest.gameObject.SetActive(isMe);
        }
        if (string.IsNullOrEmpty(userInfo.loveView))
        {
            m_tipsLoveViewStr = "你期待什么样的爱情，你如何看待爱情";
            if (isMe)
                loveView.text = m_tipsLoveViewStr;
            else
                loveView.text = "未填写";
            addLoveView.gameObject.SetActive(isMe);
            addLoveView.gameObject.SetActive(false);
        }
        else
        {
            m_tipsLoveViewStr = "";
            loveView.text = userInfo.loveView;
            addLoveView.gameObject.SetActive(false);
            addLoveView.gameObject.SetActive(isMe);
        }
        if (string.IsNullOrEmpty(userInfo.idealCompanion))
        {
            m_tipsIdealStr = "说出你对另一半的期许";
            if (isMe)
                idealCompanion.text = m_tipsIdealStr;
            else
                idealCompanion.text = "未填写";
            addIdealCompanion.gameObject.SetActive(isMe);
            editIdealCompanion.gameObject.SetActive(false);
        }
        else
        {
            m_tipsIdealStr = "";
            idealCompanion.text = userInfo.idealCompanion;
            addIdealCompanion.gameObject.SetActive(false);
            editIdealCompanion.gameObject.SetActive(isMe);
        }
    }

    // Start is called before the first frame update
    void Start()
    {
        
    }

    public void OnClickEditAboutMe()
    {
        var info = GetComponentInParent<UserHomePanel>().UIController.ShowUI<EditInfoPanel>();
        info.InitIntroduction(IntroductioType.aboutMe, "自我描述", m_tipsAboutMeStr,aboutMe.text);
    }
    public void OnClickEditHomeBackground()
    {
        var info = GetComponentInParent<UserHomePanel>().UIController.ShowUI<EditInfoPanel>();
        info.InitIntroduction(IntroductioType.familyBackground, "家庭背景", m_tipsHomeBackgroundStr, homeBackground.text);
    }
    public void OnClickEditInterest()
    {
        var info = GetComponentInParent<UserHomePanel>().UIController.ShowUI<EditInfoPanel>();
        info.InitIntroduction(IntroductioType.interest, "兴趣爱好", m_tipsInterestStr, interest.text);
    }
    public void OnClickEditLoveView()
    {
        var info = GetComponentInParent<UserHomePanel>().UIController.ShowUI<EditInfoPanel>();
        info.InitIntroduction(IntroductioType.loveView, "爱情观", m_tipsLoveViewStr, loveView.text);
    }
    public void OnClickEditIdealCompanion()
    {
        var info = GetComponentInParent<UserHomePanel>().UIController.ShowUI<EditInfoPanel>();
        info.InitIntroduction(IntroductioType.idealCompanion, "理想的另一半", m_tipsIdealStr, idealCompanion.text);
    }





    // Update is called once per frame
    void Update()
    {
        
    }
}
